<?php
/**
 * 管理中心· 管理员登陆模块的逻辑处理
 * ============================================================================
 * 版权所有 2017-2020 北京优特世纪科技有限公司，并保留所有权利。
 * 网站地址: http://www.unitewww.com;
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @since: 1.0
 * @version: 1.0
 **/
namespace Hoteladmin\Controller;
use Think\Controller;
use Hoteladmin\Model\AdminModel;
class LoginController extends Controller{
	/**
	 +--------------------------------------------------------------------------
	 * 实现管理员登录的功能
	 * @author:  XC跃
	 * @date:2018-03-09
	 +--------------------------------------------------------------------------
	 */
    public function login(){
    	//实例化相Model
    	$adidentr = new AdminModel();
        if(IS_POST){
        	//接收传值
        	$uname = trim(I('post.username'));
        	$upwds = md5(trim(I('post.password')));
        	$code  = I('post.vertify');
        	//验证码
        	if(check_verify($code)==false){
        		//$this->error("验证码错误");
        		$res = array('status'=>0,'msg'=>'图像验证码错误');
        		exit(json_encode($res));
        	}
        	$res = $adidentr->login($uname,$upwds);
        	if($res['status'] == 1){
        		$res['url'] =  urldecode("/Hoteladmin/Index/index");
        		$auth = array(
        		    'usid'   => $res['result']['ad_id'],
        		    'usname' => $res['result']['ad_name'],
        		    'ustime' => $res['result']['ad_ltime'],
        		    'usrole' => $res['result']['ad_rid'],
        		);
        		session('admin_auth', $auth);
        		session('admin_auth_sign', data_auth_sign($auth));
        		//登陆后记录操作日志
        		addLog($res['result']['ad_name'],'1','2','登陆后台系统！');
        	}
        	exit(json_encode($res));
        }else{
        	$this->display();
        }
    }
    /**
     +--------------------------------------------------------------------------
     * 实现验证码的获取
     * @author: XC跃
     * @date :2018-03-01
     +--------------------------------------------------------------------------
     */
    public function vertify(){
        $config = array(
            'fontSize' => 35,
            'length'   => 4,
            'useCurve' => false,
            'useNoise' => false,
            'fontttf'  => '5.ttf',
        );
        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }
    /**
     +--------------------------------------------------------------------------
     * 实现获取会员用户名的功能
     * @author:  XC跃
     * @date :2018-03-13
     +--------------------------------------------------------------------------
     */
    public function verUserName(){
        $usid = I('post.id');
        $ures = M('user')->where("`us_uid`='".$usid."' or `us_phone`='".$usid."'")->find();
        if('0'!=count($ures)){
            $res = array('status'=>1,'msg'=>$ures['us_name'],'uid'=>$ures['us_uid']);
        }else{
            $res = array('status'=>-1,'msg'=>'查无此人');
        }
        exit(json_encode($res));
    }
    /**
     +--------------------------------------------------------------------------
     * 实现更改数据表的状态（如：推荐，显示，隐藏等）
     * @author:  XC跃
     * @date :2018-03-13
     +--------------------------------------------------------------------------
     */
    public function updateState(){
        define('AID',is_login('admin_auth', 'admin_auth_sign'));
        if(!AID){// 还没登录 跳转到登录页面
            $this->redirect('Admin/Login/login');
        }
        //更改状态
        $re = M(I('table'))->where(I('where'))->save(array(I('field')=>I('value')));
        //echo M(I('table'))->getLastSql();
        if($re>0 && I('cue')!=''){
            $res = array('status'=>1,'msg'=>I('cue').'成功');
            exit(json_encode($res));
        }
    }
    /**
     +--------------------------------------------------------------------------
     * 实现删除指定一条数据的功能
     * @author:  XC跃
     * @date :2018-03-13
     +--------------------------------------------------------------------------
     */
    public function delOneData(){
        define('AID',is_login('admin_auth', 'admin_auth_sign'));
        if(!AID){// 还没登录 跳转到登录页面
            $this->redirect('Admin/Login/login');
        }
        //执行
        M(I('table'))->where(I('where'))->delete();
    }
}